package com.dalimao.floateutil.widget;

import ohos.agp.components.Attr;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import ohos.app.Context;

public class CircularView extends Component implements Component.DrawTask {

    Paint mPaint;
    public CircularView(Context context) {
        this(context,null);
    }

    public CircularView(Context context, AttrSet attrs) {
        this(context, attrs,null);
    }

    public CircularView(Context context, AttrSet attrs, String defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mPaint=new Paint();
        //抗锯齿
        mPaint.setAntiAlias(true);
        //防抖动
        mPaint.setDither(true);
        addDrawTask(this);
    }


    @Override
    public void onDraw(Component component, Canvas canvas) {
        int cx=getWidth()/2;
        int cy=getHeight()/2;
        //开始画圆
        canvas.drawCircle(cx,cy,cx,mPaint);
    }

    //设置圆的颜色
    public void setColor(Color color){
        mPaint.setColor(color);
        invalidate();
    }
    //获取当前圆的颜色
    public Color getColor(){
        return mPaint.getColor();
    }
}